package com.longcai.piaojia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.AppointmentListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class AppointmentAdapter extends ArrayAdapter<AppointmentListGet.OrderEntity> {

    private Context context;
    private LayoutInflater layoutInflater;
    private EnvaluateIntef envaluateIntef;

    public AppointmentAdapter(Context context, List<AppointmentListGet.OrderEntity> lists) {
        super(context, 0, lists);

        layoutInflater = LayoutInflater.from(context);

        this.context = context;

        envaluateIntef = (EnvaluateIntef) context;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        AppointmentListGet.OrderEntity orderEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_appointment_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.item_appointment_name_tv.setText(orderEntity.title);
        viewHolder.item_appointment_state_tv.setText(orderEntity.checkinfo.equals("2") ? "待出票" : "已出票");
        viewHolder.item_appointment_envaluate_tv.setVisibility(orderEntity.evaluate_status.equals("1") || orderEntity.checkinfo.equals("2") ? View.GONE : View.VISIBLE);
        viewHolder.item_appointment_time_tv.setText("预约时间：" + orderEntity.datetimes);
        viewHolder.item_appointment_num_tv.setText("预约场次：" + orderEntity.time_tip + "" + orderEntity.starttime + "-" + orderEntity.endtime);
        viewHolder.item_appointment_mumber_tv.setText("成员信息：" + orderEntity.name + (orderEntity.ischild.equals("1") ? " （含儿童一名）" : " ") + orderEntity.mobile);

        viewHolder.item_appointment_envaluate_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                envaluateIntef.envaluate(position);
            }
        });


        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_appointment_name_tv) private TextView item_appointment_name_tv;
        @BoundView(R.id.item_appointment_state_tv) private TextView item_appointment_state_tv;
        @BoundView(R.id.item_appointment_envaluate_tv) private TextView item_appointment_envaluate_tv;
        @BoundView(R.id.item_appointment_time_tv) private TextView item_appointment_time_tv;
        @BoundView(R.id.item_appointment_num_tv) private TextView item_appointment_num_tv;
        @BoundView(R.id.item_appointment_mumber_tv) private TextView item_appointment_mumber_tv;
    }

    public interface EnvaluateIntef {

        void envaluate (int pos);

    }
}
